import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    name:'Login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: '清防蜡管控平台',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '清防蜡管控平台', icon: 'dashboard' }
    }]
  },

  {
    path: '/comprehensiveQuery',
    component: Layout,
    name: '单井综合查询',
    meta: { title: '单井综合查询', icon: 'el-icon-s-help' },
    children: [{
      path: 'http://djwtzd.iosp.xjyt.petrochina/djwtzd/?access_token=token/oilWellDetailsIndex?well_id7',
      name: '综合数据',
      // component: () => import('@/views/well_comprehensiveQuery/comprehensiveQuery'),
      meta: { title: '综合数据', icon: 'el-icon-s-help' }
    },
    {
      path: 'components/component3',
      name: '载荷差数据',
      component: () => import('@/views/well_comprehensiveQuery/components/component3'),
      meta: { title: '载荷差数据', icon: 'el-icon-s-help' }
    }
    ]
  },
  {
    path: '/abnormalWells',
    component: Layout,
    name: '异常井',
    meta: { title: '异常井', icon: 'el-icon-s-help' },
    children: [
      // {
      //   path: 'periodicWarning',
      //   name: '超周期预警',
      //   component: () => import('@/views/well_abnormalWells/periodicWarning'),
      //   meta: { title: '超周期预警', icon: 'table' }
      // },
      {
        path: 'loadDiffWarning',
        name: '周期预警',
        component: () => import('@/views/well_abnormalWells/loadDiffWarning'),
        meta: { title: '周期预警', icon: 'table' }
      },
      {
        path: 'qualityWarning',
        name: '质量预警',
        component: () => import('@/views/well_abnormalWells/qualityWarning'),
        meta: { title: '质量预警', icon: 'table' }
      },
      {
        path: 'warningStatistics',
        name: '预警统计',
        component: () => import('@/views/well_abnormalWells/warningStatistics'),
        meta: { title: '预警统计', icon: 'table' }
      }
    ]
  },

  {
    path: '/ledger',
    component: Layout,
    name: '清防蜡台账',
    meta: { title: '清防蜡台账', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'query',
        name: '台账查询',
        component: () => import('@/views/well_ledger/queryLedger'),
        meta: { title: '台账查询', icon: 'table' }
      },
      {
        path: 'upload',
        name: '上传台账',
        component: () => import('@/views/well_ledger/uploadLedger'),
        meta: { title: '上传台账', icon: 'table' }
      },
      // {
      //   path: 'insert',
      //   name: '新增记录',
      //   component: () => import('@/views/well_ledger/insertLedger'),
      //   meta: { title: '新增记录', icon: 'table' }
      // }
    ]
  },

  {
    path: '/runManagement',
    component: Layout,
    name: '清防蜡运行管理',
    meta: { title: '清防蜡运行管理', icon: 'el-icon-s-help' },
    children: [
      // {
      //   path: 'query',
      //   name: '台账查询',
      //   component: () => import('@/views/well_ledger/queryLedger'),
      //   meta: { title: '台账查询', icon: 'table' }
      // },
      // {
      //   path: 'upload',
      //   name: '上传台账',
      //   component: () => import('@/views/well_ledger/uploadLedger'),
      //   meta: { title: '上传台账', icon: 'table' }
      // },
      {
        path: 'implementation',
        name: '清防蜡实施情况',
        component: () => import('@/views/well_runManagement/implementation'),
        meta: { title: '清防蜡设计', icon: 'table' }
      },
      {
        path: 'normalInsert',
        hidden: true,
        name: '周期清防蜡设计',
        component: () => import('@/views/well_design/normalDesInsert'),
        meta: { title: '周期清防蜡设计', icon: 'table', activeMenu: '/runManagement/implementation' }
      },
      {
        path: 'implementDetails',
        name: '清防蜡工作安排',
        component: () => import('@/views/well_runManagement/implementDetails'),
        meta: { title: '清防蜡工作安排', icon: 'table' }
      },
      {
        path: 'implementStatistics',
        name: '清防蜡实施统计',
        component: () => import('@/views/well_runManagement/implementStatistics'),
        meta: { title: '清防蜡实施统计', icon: 'table' }
      }
    ]
  },
  {
    path: '/antiWaxPlan',
    component: Layout,
    name: '清防蜡计划',
    meta:{title: '清防蜡计划', icon: 'el-icon-s-help'},
    children: [
      {
        path: '/antiWaxPlan/planDay',
        name: '清防蜡日计划',
        component: {render(c){return c('router-view')}},
        redirect: '/antiWaxPlan/planDay',
        meta: { title: '清防蜡日计划', icon: 'el-icon-s-help' },
        children: [
          {
            path: 'dayPlan',
            name: '正常井日计划',
            component: () => import('@/views/antiWaxPlan/planDay/dayPlan.vue'),
            meta: { title: '正常井日计划', icon: 'table' }
          },
          // {
          //   path: 'weekPlan',
          //   name: '异常井日计划',
          //   component: () => import('@/views/antiWaxPlan/planDay/expDayPlan.vue'),
          //   meta: { title: '异常井日计划', icon: 'table' }
          // },
        ]
      },
      {
        path: 'weekPlan',
        name: '清防蜡周计划',
        component: () => import('@/views/antiWaxPlan/weekPlan.vue'),
        meta: { title: '清防蜡周计划', icon: 'el-icon-s-help' }
      },
      {
        path: 'monthPlan',
        name: '清防蜡月计划',
        component: () => import('@/views/antiWaxPlan/monthPlan.vue'),
        meta: { title: '清防蜡月计划', icon: 'el-icon-s-help' }
      }
    ]
  },
  {
    path: '/abnormalCleaningAntiWax',
    component: Layout,
    name: '异常井清防蜡',
    meta: { title: '异常井清防蜡', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'abnormalApplication',
        name: '异常井清防蜡申请',
        component: () => import('@/views/well_abnormalCleaningAntiWax/abnormalQueryApply'),
        meta: { title: '异常井清防蜡申请', icon: 'table' }
      },
      {
        path: 'abnormalWellImplementation',
        name: '异常井清防蜡实施情况',
        component: () => import('@/views/well_abnormalCleaningAntiWax/abnormalWellImplementation'),
        meta: { title: '异常井清防蜡实施情况', icon: 'table' }
      },
      {
        path: 'abnormalWellStatistics',
        name: '异常井清防蜡统计',
        component: () => import('@/views/well_abnormalCleaningAntiWax/abnormalWellStatistics'),
        meta: { title: '异常井清防蜡统计', icon: 'table' }
      }
    ]
  },
  {
    path: '/check',
    component: Layout,
    name: '清防蜡巡检',
    meta: { title: '清防蜡巡检', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'table',
        name: '油井巡检',
        component: () => import('@/views/well_check/queryCheck'),
        meta: { title: '油井巡检', icon: 'el-icon-s-help' }
      }
    ]
  },
  {
    path: '/quality',
    component: Layout,
    name: '清防蜡质量',
    meta: { title: '清防蜡质量', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'http://10.72.64.216:8080/NewQueryTool.aspx?id=DOSING_VEHICLE_BJV&type=selfce&un=liqinxian',
        name: '清防蜡质量曲线',
        meta: { title: '清防蜡质量曲线', icon: 'table' }
      },
      {
        path: 'http://10.72.64.216:8080/NewQueryTool.aspx?id=RHQZLV&type=selfce&un=liqinxian',
        name: '热化清质量日报',
        meta: { title: '热化清质量日报', icon: 'table' }
      },
      {
        path: 'http://10.72.64.216:8080/NewQueryTool.aspx?id=RHQRB&type=selfce&un=liqinxian',
        name: '热化清车工作日报',
        meta: { title: '热化清车工作日报', icon: 'table' }
      },
      // {
      //   path:'wellLine',
      //   name: '清防蜡质量',
      //   component: () => import('@/views/well_quality/wellLine.vue'),
      //   meta: { title: '清防蜡质量', icon: 'table'}
      // }
    ]
  },
  {
    path: '/medicine',
    component:Layout,
    name: '药剂管理',
    meta: {
      title: '药剂管理', icon: 'el-icon-s-help'
    },
    children: [{
      path: 'http://10.72.64.216:8080/NewQueryTool.aspx?id=lhz_jylv&type=selfce&un=liqinxian',
      name: '药剂管理',
      // component:() => import('@/views/medicine/addMedicine.vue'),
      meta: {title: '药剂管理', icon: 'table'}
    }]
  },
  {
    path: '/statistics',
    component: Layout,
    name: '汇总统计',
    meta: { title: '汇总统计', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'warningStatistics',
        name: '预警统计',
        component: () => import('@/views/well_statistics/warningStatistics'),
        meta: { title: '预警统计', icon: 'table' }
      },
      {
        path: 'runStatistics',
        name: '运行统计',
        component: () => import('@/views/well_statistics/runStatistics'),
        meta: { title: '运行统计', icon: 'table' }
      },
      {
        path: 'ProcessStatistics',
        name: '工艺统计',
        component: () => import('@/views/well_statistics/processStatistics'),
        meta: { title: '工艺统计', icon: 'table' }
      },
      {
        path: 'cycleStatistics',
        name: '周期统计',
        component: () => import('@/views/well_statistics/cycleStatistics'),
        meta: { title: '周期统计', icon: 'table' }
      }
    ]
  },
  {
    path: '/userManager',
    component: Layout,
    name: '用户管理',
    meta: { title: '用户管理', icon: 'el-icon-user' },
    children: [
      {
        path: 'userQuery',
        name: '用户管理',
        component: () => import('@/views/user/userManager'),
        meta: { title: '用户管理', icon: 'el-icon-user' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

// router.beforeEach((to, from, next) =>{
//   const token = localStorage.getItem("Token")
//   if(to.name !== 'Login' && !token) next({name: 'Login'})
//   else next()
// })

export default router
